/**
 * 
 */
package com.bhugo.tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.bhugo.IPStore;

/**
 * @author benjamin
 *
 */
public class IPStoreTest{

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}	
	@Test (expected = IllegalArgumentException.class)
	public void failedConstructionUpperLimit() {
		String[] address = {"192","256","0","1"};
		IPStore ip = new IPStore(address);
	}
	@Test (expected = IllegalArgumentException.class)
	public void failedConstructionLowerLimit() {
		String[] address = {"192","255","-1","1"};
		IPStore ip = new IPStore(address);
	}
	@Test (expected = IllegalArgumentException.class)
	public void failedConstructionNumArgs() {
		String[] address = {"192","255","0","1","2"};
		IPStore ip = new IPStore(address);
	}
	@Test
	public void correctConstruction() {
		String[] address = {"192","168","23","1"};
		IPStore ip = new IPStore(address);
		assertEquals("Internal representation of 192.168.23.1 must equal 0xC0A81701",0xC0A81701,ip.get_addr());
	}
	@Test
	public void correctToStringConstruction() {
		String[] address = {"192","168","23","1"};
		IPStore ip = new IPStore(address);
		assertEquals("Tostring should reconstruct 192.168.23.1 from 0xC0A81701","192.168.23.1",ip.toString());
	}
	@Test (expected = IllegalArgumentException.class)
	public void ipThrowInvalidArgException() {
		String[] address = {"192","168","23","1"};
		IPStore ip = new IPStore(address);
		Object p = new Object();
		ip.equals(p);
	}
	@Test
	public void ipEqualsIp() {
		String[] address = {"192","168","23","1"};
		IPStore ip = new IPStore(address);		
		IPStore ipPrime = new IPStore(address);
		String[] addressPrime = {"192","110","23","1"};
		IPStore ipPrimePrime = new IPStore(addressPrime);
		assertTrue("\"192.168.23.1 should equal 192.168.23.1",ip.equals(ipPrime));
		assertFalse("\"192.168.23.1 should not equal 192.110.23.1",ip.equals(ipPrimePrime));
	}
}
